package com.study.common;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * Created with IDEA
 * <p>
 * 全局异常处理类
 *
 * @author xubo
 * create: 2018-12-19 16:09
 */
@Slf4j
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {

    //在返回自定义相应类的情况下必须有，这是@ControllerAdvice注解的规定

    /**
     * 全局异常
     *
     * @param e error
     * @return error code
     */
    @ExceptionHandler
    public CommonResponse<Void> exceptionHandler(Exception e) {
        log.error("全局异常处理 " + e.getMessage(), e);
        return new CommonResponse<>(-1, "system error", e);
    }

}
